<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base],
        components: {},
        data() {
            return {
                load:true,
                form: {

                    isOpenInvoice: 0,
                    isAddTax: 0,
                    invoiceSettingItemLst: []
                },

            };
        },
        methods: {

            // 初始化
            init() {
                this.getData();
            },
            blur(index_) {
                if (this.form.invoiceSettingItemLst[index_].taxRate == undefined) {
                    this.form.invoiceSettingItemLst[index_].taxRate= 0;
                }
            },

            // 获取内容信息
            async getData() {
                this.load = true;
                let _data = await this.$vFN.Http.post({
                    url: "mall-site-portal/invoice-setting/getItem",
                },window);
                if (_data._ok) {
                    for (let i in this.form) {
                        this.form[i] = _data.data[i]
                    }
                }
                this.load = false;
            },

            // 保存
            async submit() {
                if (this.form.isOpenInvoice == 1) {
                    let _is = 0;
                    this.form.invoiceSettingItemLst.forEach(item => {
                        if (item.isOpen != 0) {
                            _is += 1
                        }
                    })
                    if (_is <= 0) {
                        this.$vFN.Tools.messageError("可开具发票类型至少配置一项");
                        return
                    }
                }
                this.load = true;
                let _data = await this.$vFN.Http.post({
                    url: "mall-site-portal/invoice-setting/saveOrUpdate",
                    data: this.form,
                },window);
                if (_data._ok) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                    this.init();
                }
                this.load = false;
            },

        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>